﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using Framework.GameStateManagment.GameScreens;

namespace Framework.GameStateManagment
{
    public class GameStateManagment
    {

        /// 0 = Loadingscreen at the beginning
        /// 1 = Mainmenue
        /// 2 = Loadingscreen for the game
        /// 3 = SinglePlayer
        /// 4 = ESC_Menue
        /// 5 = GameOver
        /// 6 = Multiplayer
        /// 7 = Options

        #region Variables and accesors

        // 0 = Loadingscreen at the beginning
        // 1 = Mainmenue
        // 2 = Loadingscreen for the game
        // 3 = SinglePlayer
        // 4 = ESC_Menue
        // 5 = GameOver
        // 6 = Multiplayer
        // 7 = Options
        private static Game _game;

        private static Int32 _gameState;

        private static SpriteBatch _spriteBatch;

        private static GameScreen[] _gameScreens;

        private static bool _endGame;

        public static Int32 GameState
        {
            get { return _gameState; }
            set { _gameState = value; }
        }

        public static SpriteBatch SpriteBatch
        {
            get { return _spriteBatch; }
            set { _spriteBatch = value; }
        }

        static GameScreen[] GameScreens
        {
            get { return _gameScreens; }
            set { _gameScreens = value; }
        }

        public static bool EndGame
        {
            get { return _endGame; }
            set { _endGame = value; }
        }

        #endregion

        public static void Init(SpriteBatch SpriteBatch, Game game)
        {
            _game = game;
            _spriteBatch = SpriteBatch;
            Init();
        }

        public static void Init()
        {
            _gameState = 0;

            // Exit the gmae
            _endGame = false;

            // 0 = Loadingscreen at the beginning
            // 1 = Mainmenue
            // 2 = Loadingscreen for the game
            // 3 = SinglePlayer
            // 4 = ESC_Menue
            // 5 = GameOver
            // 6 = Multiplayer
            // 7 = Options
            _gameScreens = new GameScreen[8];
            _gameScreens[0] = new LoadingScreenBegin();
            _gameScreens[1] = new MainMenue();
            _gameScreens[2] = new LoadingScreenGame();
            _gameScreens[3] = new SinglePlayer();
            _gameScreens[4] = new ESC_Menue();
            _gameScreens[5] = new GameOver();
            _gameScreens[6] = new MultiPlayer();
            _gameScreens[7] = new Options();

            for (int i = 0; i < _gameScreens.Length; i++)
            {
                _gameScreens[i].Init();
            }
        }

        public static void LoadContent(ContentManager Content)
        {
            for (int i = 0; i < _gameScreens.Length; i++)
            {
                if (i == 3 || i == 6)
                {
                    _gameScreens[i].Init(_game);
                }
                _gameScreens[i].LoadContent(Content);
            }
        }

        public static void Update()
        {
            _gameScreens[_gameState].Update();
        }

        public static void Draw()
        {
            _gameScreens[_gameState].Draw();
        }
    }
}
